package com.hly.musicbackground.model.movies.rest;

import com.hly.musicbackground.Utils.RequestContextUtils;
import com.hly.musicbackground.domain.Movies;
import com.hly.musicbackground.model.movies.params.MoviesLinkParams;
import com.hly.musicbackground.model.movies.service.MoviesLinkService;
import com.hly.musicbackground.model.movies.service.MoviesService;
import com.hly.musicbackground.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 影视收藏、足迹
 * */
@RestController
@RequestMapping("/api/moviesLink")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "影视收藏/足迹")
public class MoviesLinkController {

    private final MoviesLinkService moviesLinkService;
    private final MoviesService moviesService;

    @GetMapping("/user")
    @ApiOperation(value = "获取影视收藏/足迹列表")
    public Result<List<Movies>> getCollect(@RequestParam(value = "limit", defaultValue = "10") int limit,
                                               @RequestParam(value = "page", defaultValue = "1") int page,
                                               @RequestParam(value = "type", defaultValue = "foot") int type){
        int uid = RequestContextUtils.getUser().getUserId();
        List<Movies> list = moviesService.getMoviesLinkList(limit, page ,type, uid);
        return Result.ok(list);
    }

    @PostMapping("/emit")
    @ApiOperation(value = "添加/修改影视收藏/足迹")
    public Result addCollect(@RequestBody MoviesLinkParams params){
        int uid = RequestContextUtils.getUser().getUserId();
        moviesLinkService.emitMoviesLink(params, uid);
        return Result.ok();
    }

    @PostMapping("/dels/{ids}")
    @ApiOperation(value = "批量删除")
    public Result delCollect(@PathVariable("ids") String ids){
        int uid = RequestContextUtils.getUser().getUserId();
        moviesLinkService.delMoviesLink(uid, Arrays.asList(ids.split(",")));
        return Result.ok();
    }

}
